<template>
  <div class="image-upload">
    <el-upload ref="ImageUpload" :action="action" list-type="picture-card" :on-preview="handlePictureCardPreview">
      <el-button icon=" el-icon-upload2">
        上传证书
        
      </el-button>
      <div class="image-upload_tip" @click.stop.prevent>只支持JPG格式，大小不要超过1M</div>
      <!-- <template #file="{ file }">
        {{ file }}
      </template> -->
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'imgUpload',
  props: {
    action: {
      type: String,
      default: "http://localhost:3000/uploadImage"
    }
  },
  data() {
    return {
      list: [],
      dialogVisible: false,
      dialogImageUrl: ''
    }
  },
  mounted() {
    console.log(this.$refs.ImageUpload);
    const upload = this.$refs.ImageUpload.$el.querySelector('.el-upload')
    console.log(upload);
    upload.setAttribute('class', 'el-upload')
  },
  methods: {
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    }
  }
}
</script>

<style scoped lang='less'>
.image-upload {
  width: 100%;
  background: pink;

  &_tip {
    position: absolute;
    margin-top: 10px;
    color: #000;
    user-select: none;
    cursor: auto;
  }
}
</style>